home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Include / GuiMonthCal.au3 < prev    next >
Encoding:
Text File  |  2007-09-08  |  16.6 KB  |  366 lines

  1. #include-once
  2. #include <DateTimeConstants.au3>
  3. #include <Misc.au3>
  4. ; ------------------------------------------------------------------------------
  5. ;
  6. ; AutoIt Version: 3.2.3++
  7. ; Language:       English
  8. ; Description:    Functions that assist with MonthCal.
  9. ;
  10. ; ------------------------------------------------------------------------------
  11.  
  12.  
  13. ; function list
  14. ;===============================================================================
  15. ;_GUICtrlMonthCalGet1stDOW
  16. ;_GUICtrlMonthCalGetColor
  17. ;_GUICtrlMonthCalGetMaxSelCount
  18. ;_GUICtrlMonthCalGetMaxTodayWidth
  19. ;_GUICtrlMonthCalGetMinReqRECT
  20. ;_GUICtrlMonthCalGetDelta
  21. ;_GUICtrlMonthCalSetColor
  22. ;_GUICtrlMonthCalSet1stDOW
  23. ;_GUICtrlMonthCalSetMaxSelCount
  24. ;_GUICtrlMonthCalSetDelta
  25. ;===============================================================================
  26.  
  27. ;===============================================================================
  28. ;
  29. ; Description:            _GUICtrlMonthCalGet1stDOW
  30. ; Parameter(s):        $h_monthcal - controlID
  31. ; Requirement:            None.
  32. ; Return Value(s):    String of 1st Day Of Week
  33. ; User CallTip:        _GUICtrlMonthCalGet1stDOW($h_monthcal) Retrieves the first day of the week for a month calendar control. (required: <GuiMonthCal.au3>)
  34. ; Author(s):            Gary Frost (custompcs at charter dot net)
  35. ; Note(s):
  36. ;
  37. ;===============================================================================
  38. Func _GUICtrlMonthCalGet1stDOW($h_monthcal)
  39.     If Not _IsClassName ($h_monthcal, "SysMonthCal32") Then Return SetError(-1, -1, "")
  40.     Local $result
  41.     If IsHWnd($h_monthcal) Then
  42.         $result = _SendMessage($h_monthcal, $MCM_GETFIRSTDAYOFWEEK)
  43.     Else
  44.         $result = GUICtrlSendMsg($h_monthcal, $MCM_GETFIRSTDAYOFWEEK, 0, 0)
  45.     EndIf
  46.     Select
  47.         Case $result = 0
  48.             Return "Monday"
  49.         Case $result = 1
  50.             Return "Tuesday"
  51.         Case $result = 2
  52.             Return "Wednesday"
  53.         Case $result = 3
  54.             Return "Thursday"
  55.         Case $result = 4
  56.             Return "Friday"
  57.         Case $result = 5
  58.             Return "Saturday"
  59.         Case $result = 6
  60.             Return "Sunday"
  61.     EndSelect
  62. EndFunc   ;==>_GUICtrlMonthCalGet1stDOW
  63.  
  64. ;===============================================================================
  65. ;
  66. ; Description:            _GUICtrlMonthCalGetColor
  67. ; Parameter(s):        $h_monthcal - controlID
  68. ;                            $i_color - Value of type int specifying which month calendar color to retrieve.
  69. ; Requirement:            None.
  70. ; Return Value(s):    Array containing the color
  71. ; User CallTip:        _GUICtrlMonthCalGetColor($h_monthcal, $i_color) Retrieves the color for a given portion of a month calendar control. (required: <GuiMonthCal.au3>)
  72. ; Author(s):            Gary Frost (custompcs at charter dot net)
  73. ; Note(s):                $i_color this value can be one of the following:
  74. ;                                $MCSC_BACKGROUND
  75. ;                                    Retrieve the background color displayed between months.
  76. ;                                $MCSC_MONTHBK
  77. ;                                    Retrieve the background color displayed within the month.
  78. ;                                $MCSC_TEXT
  79. ;                                    Retrieve the color used to display text within a month.
  80. ;                                $MCSC_TITLEBK
  81. ;                                    Retrieve the background color displayed in the calendar's title.
  82. ;                                $MCSC_TITLETEXT
  83. ;                                    Retrieve the color used to display text within the calendar's title.
  84. ;                                $MCSC_TRAILINGTEXT
  85. ;                                    Retrieve the color used to display header day and trailing day text.
  86. ;                                    Header and trailing days are the days from the previous and following
  87. ;                                    months that appear on the current month calendar.
  88. ;
  89. ;                            $array[0] - contains the number returned
  90. ;                            $array[1] - contains COLORREF rgbcolor
  91. ;                            $array[2] - contains Hex BGR color
  92. ;                            $array[3] - contains Hex RGB color
  93. ;===============================================================================
  94. Func _GUICtrlMonthCalGetColor($h_monthcal, $i_color)
  95.     If Not _IsClassName ($h_monthcal, "SysMonthCal32") Then Return SetError(-1, -1, -1)
  96.     Local $result, $a_result[4]
  97.     $a_result[0] = 3
  98.     If IsHWnd($h_monthcal) Then
  99.         $result = _SendMessage($h_monthcal, $MCM_GETCOLOR, $i_color)
  100.     Else
  101.         $result = GUICtrlSendMsg($h_monthcal, $MCM_GETCOLOR, $i_color, 0)
  102.     EndIf
  103.     $a_result[1] = Int($result) ; COLORREF rgbcolor
  104.     $a_result[2] = "0x" & Hex(String($result), 6) ; Hex BGR color
  105.     $a_result[3] = Hex(String($result), 6)
  106.     $a_result[3] = "0x" & StringMid($a_result[3], 5, 2) & StringMid($a_result[3], 3, 2) & StringMid($a_result[3], 1, 2) ; Hex RGB Color
  107.     Return $a_result
  108. EndFunc   ;==>_GUICtrlMonthCalGetColor
  109.  
  110. ;===============================================================================
  111. ;
  112. ; Description:            _GUICtrlMonthCalGetDelta
  113. ; Parameter(s):        $h_monthcal - controlID
  114. ; Requirement:            None.
  115. ; Return Value(s):    If the month delta was previously set using the _GUICtrlMonthCalSetDelta,
  116. ;                                returns an INT value that represents the month calendar's current scroll rate.
  117. ;                            If the month delta was not previously set using the _GUICtrlMonthCalSetDelta,
  118. ;                                or the month delta was reset to the default,
  119. ;                                returns an INT value that represents the current number of months visible.
  120. ; User CallTip:        _GUICtrlMonthCalGetDelta($h_monthcal) Retrieves the scroll rate for a month calendar control. (required: <GuiMonthCal.au3>)
  121. ; Author(s):            Gary Frost (custompcs at charter dot net)
  122. ; Note(s):
  123. ;
  124. ;===============================================================================
  125. Func _GUICtrlMonthCalGetDelta($h_monthcal)
  126.     If Not _IsClassName ($h_monthcal, "SysMonthCal32") Then Return SetError(-1, -1, -1)
  127.     If IsHWnd($h_monthcal) Then
  128.         Return _SendMessage($h_monthcal, $MCM_GETMONTHDELTA)
  129.     Else
  130.         Return GUICtrlSendMsg($h_monthcal, $MCM_GETMONTHDELTA, 0, 0)
  131.     EndIf
  132. EndFunc   ;==>_GUICtrlMonthCalGetDelta
  133.  
  134. ;===============================================================================
  135. ;
  136. ; Description:            _GUICtrlMonthCalGetMaxSelCount
  137. ; Parameter(s):        $h_monthcal - controlID
  138. ; Requirement:            None.
  139. ; Return Value(s):    Returns an INT value that represents the total number of days that can be selected for the control.
  140. ; User CallTip:        _GUICtrlMonthCalGetMaxSelCount($h_monthcal) Retrieves the maximum date range that can be selected in a month calendar control. (required: <GuiMonthCal.au3>)
  141. ; Author(s):            Gary Frost (custompcs at charter dot net)
  142. ; Note(s):
  143. ;
  144. ;===============================================================================
  145. Func _GUICtrlMonthCalGetMaxSelCount($h_monthcal)
  146.     If Not _IsClassName ($h_monthcal, "SysMonthCal32") Then Return SetError(-1, -1, -1)
  147.     If IsHWnd($h_monthcal) Then
  148.         Return _SendMessage($h_monthcal, $MCM_GETMAXSELCOUNT)
  149.     Else
  150.         Return GUICtrlSendMsg($h_monthcal, $MCM_GETMAXSELCOUNT, 0, 0)
  151.     EndIf
  152. EndFunc   ;==>_GUICtrlMonthCalGetMaxSelCount
  153.  
  154. ;===============================================================================
  155. ;
  156. ; Description:            _GUICtrlMonthCalGetMaxTodayWidth
  157. ; Parameter(s):        $h_monthcal - controlID
  158. ; Requirement:            None.
  159. ; Return Value(s):    Returns the width of the "today" string, in pixels.
  160. ; User CallTip:        _GUICtrlMonthCalGetMaxTodayWidth($h_monthcal) Retrieves the maximum width of the "today" string in a month calendar control. (required: <GuiMonthCal.au3>)
  161. ; Author(s):            Gary Frost (custompcs at charter dot net)
  162. ; Note(s):
  163. ;
  164. ;===============================================================================
  165. Func _GUICtrlMonthCalGetMaxTodayWidth($h_monthcal)
  166.     If Not _IsClassName ($h_monthcal, "SysMonthCal32") Then Return SetError(-1, -1, -1)
  167.     If IsHWnd($h_monthcal) Then
  168.         Return _SendMessage($h_monthcal, $MCM_GETMAXTODAYWIDTH)
  169.     Else
  170.         Return GUICtrlSendMsg($h_monthcal, $MCM_GETMAXTODAYWIDTH, 0, 0)
  171.     EndIf
  172. EndFunc   ;==>_GUICtrlMonthCalGetMaxTodayWidth
  173.  
  174. ;===============================================================================
  175. ;
  176. ; Description:            _GUICtrlMonthCalGetMinReqRECT
  177. ; Parameter(s):        $h_monthcal - controlID
  178. ; Requirement:            None.
  179. ; Return Value(s):    Array containing the RECT, first element ($array[0]) contains the number of elements
  180. ;                            if error -1 is returned
  181. ; User CallTip:        _GUICtrlMonthCalGetMinReqRECT($h_monthcal) Retrieves the minimum size required to display a full month in a month calendar control.  (required: <GuiMonthCal.au3>)
  182. ; Author(s):            Gary Frost (custompcs at charter dot net)
  183. ; Note(s):                The minimum required window size for a month calendar control depends on the currently selected font,
  184. ;                            control styles, system metrics, and regional settings.
  185. ;
  186. ;===============================================================================
  187. Func _GUICtrlMonthCalGetMinReqRECT($h_monthcal)
  188.     If Not _IsClassName ($h_monthcal, "SysMonthCal32") Then Return SetError(-1, -1, -1)
  189. ;~     typedef struct _RECT {
  190. ;~       LONG left;
  191. ;~       LONG top;
  192. ;~       LONG right;
  193. ;~       LONG bottom;
  194. ;~     } RECT, *PRECT;
  195.     Local $RECT = "int;int;int;int"
  196.     Local $left = 1
  197.     Local $top = 2
  198.     Local $right = 3
  199.     Local $bottom = 4
  200.     Local $struct_RECT, $v_ret
  201.     $struct_RECT = DllStructCreate($RECT)
  202.     If @error Then Return SetError(-1, -1, -1)
  203.     If IsHWnd($h_monthcal) Then
  204.         $v_ret = _SendMessage($h_monthcal, $MCM_GETMINREQRECT, 0, DllStructGetPtr($struct_RECT), 0, "int", "ptr")
  205.     Else
  206.         $v_ret = GUICtrlSendMsg($h_monthcal, $MCM_GETMINREQRECT, 0, DllStructGetPtr($struct_RECT))
  207.     EndIf
  208.     If (Not $v_ret) Then Return SetError(-1, -1, -1)
  209.     Local $array = StringSplit(DllStructGetData($struct_RECT, $left) & "," & DllStructGetData($struct_RECT, $top) & "," & DllStructGetData($struct_RECT, $right) & "," & DllStructGetData($struct_RECT, $bottom), ",")
  210.     Return $array
  211. EndFunc   ;==>_GUICtrlMonthCalGetMinReqRECT
  212.  
  213. ;===============================================================================
  214. ;
  215. ; Description:            _GUICtrlMonthCalSet1stDOW
  216. ; Parameter(s):        $h_monthcal - controlID
  217. ;                            $s_day - Value representing which day is to be set as the first day of the week.
  218. ; Requirement:            None.
  219. ; Return Value(s):    The previous first day of the week.
  220. ;                            if error -1 is returned
  221. ; User CallTip:        _GUICtrlMonthCalSet1stDOW($h_monthcal, $s_day) Sets the first day of the week for a month calendar control. (required: <GuiMonthCal.au3>)
  222. ; Author(s):            Gary Frost (custompcs at charter dot net)
  223. ; Note(s):                $s_day:
  224. ;                                0 or "Monday"
  225. ;                                1 or "Tuesday"
  226. ;                                2 or "Wednesday"
  227. ;                                3 or "Thursday"
  228. ;                                4 or "Friday"
  229. ;                                5 or "Saturday"
  230. ;                                6 or "Sunday"
  231. ;
  232. ;===============================================================================
  233. Func _GUICtrlMonthCalSet1stDOW($h_monthcal, $s_day)
  234.     If Not _IsClassName ($h_monthcal, "SysMonthCal32") Then Return SetError(-1, -1, -1)
  235.     Local $i_day
  236.     Select
  237.         Case String($s_day) = "0" Or StringUpper($s_day) = "MONDAY"
  238.             $i_day = 0
  239.         Case String($s_day) = "1" Or StringUpper($s_day) = "TUESDAY"
  240.             $i_day = 1
  241.         Case String($s_day) = "2" Or StringUpper($s_day) = "WEDNESDAY"
  242.             $i_day = 2
  243.         Case String($s_day) = "3" Or StringUpper($s_day) = "THURSDAY"
  244.             $i_day = 3
  245.         Case String($s_day) = "4" Or StringUpper($s_day) = "FRIDAY"
  246.             $i_day = 4
  247.         Case String($s_day) = "5" Or StringUpper($s_day) = "SATURDAY"
  248.             $i_day = 5
  249.         Case String($s_day) = "6" Or StringUpper($s_day) = "SUNDAY"
  250.             $i_day = 6
  251.         Case Else
  252.             Return SetError(-1, -1, -1)
  253.     EndSelect
  254.     If IsHWnd($h_monthcal) Then
  255.         Return _SendMessage($h_monthcal, $MCM_SETFIRSTDAYOFWEEK, 0, $i_day)
  256.     Else
  257.         Return GUICtrlSendMsg($h_monthcal, $MCM_SETFIRSTDAYOFWEEK, 0, $i_day)
  258.     EndIf
  259. EndFunc   ;==>_GUICtrlMonthCalSet1stDOW
  260.  
  261. ;===============================================================================
  262. ;
  263. ; Description:            _GUICtrlMonthCalSetColor
  264. ; Parameter(s):        $h_monthcal - controlID
  265. ;                            $i_color - Value of type int specifying which month calendar color to set.
  266. ;                            $i_colorref - Value that represents the color that will be set for the specified area of the month calendar.
  267. ;                            $i_refType - Optional: Type of value used for $i_colorref
  268. ; Requirement:            None.
  269. ; Return Value(s):    Returns an array of the previous color setting for the specified portion of the month calendar control if successful.
  270. ;                            Otherwise, the return is -1.
  271. ; User CallTip:        _GUICtrlMonthCalSetColor($h_monthcal, $i_color, $i_colorref[, $i_refType = 0]) Sets the color for a given portion of a month calendar control. (required: <GuiMonthCal.au3>)
  272. ; Author(s):            Gary Frost (custompcs at charter dot net)
  273. ; Note(s):                $i_color this value can be one of the following:
  274. ;                                $MCSC_BACKGROUND
  275. ;                                    Set the background color displayed between months.
  276. ;                                $MCSC_MONTHBK
  277. ;                                    Set the background color displayed within the month.
  278. ;                                $MCSC_TEXT
  279. ;                                    Set the color used to display text within a month.
  280. ;                                $MCSC_TITLEBK
  281. ;                                    Set the background color displayed in the calendar's title.
  282. ;                                $MCSC_TITLETEXT
  283. ;                                    Set the color used to display text within the calendar's title.
  284. ;                                $MCSC_TRAILINGTEXT
  285. ;                                    Set the color used to display header day and trailing day text.
  286. ;                                    Header and trailing days are the days from the previous and following
  287. ;                                    months that appear on the current month calendar.
  288. ;
  289. ;                                $i_refType = 0 $i_colorref is COLORREF rgbcolor (default)
  290. ;                                $i_refType = 1 $i_colorref is Hex BGR color
  291. ;                                $i_refType = 0 $i_colorref is Hex RGB color
  292. ;
  293. ;                                Value returned:
  294. ;                                    array[0] = number of elements
  295. ;                                    array[1] = COLORREF rbgcolor
  296. ;                                    array[2] = Hex BGR color
  297. ;                                    array[3] = Hex RGB color
  298. ;
  299. ;===============================================================================
  300. Func _GUICtrlMonthCalSetColor($h_monthcal, $i_color, $i_colorref, $i_refType = 0)
  301.     If Not _IsClassName ($h_monthcal, "SysMonthCal32") Then Return SetError(-1, -1, -1)
  302.     Local $result, $a_result[4]
  303.     $a_result[0] = 3
  304.     If ($i_refType == 1) Then
  305.         $i_colorref = Int($i_colorref)
  306.     ElseIf ($i_refType == 2) Then
  307.         $i_colorref = Hex(String($i_colorref), 6)
  308.         $i_colorref = Int('0x' & StringMid($i_colorref, 5, 2) & StringMid($i_colorref, 3, 2) & StringMid($i_colorref, 1, 2))
  309.     EndIf
  310.     If IsHWnd($h_monthcal) Then
  311.         $result = _SendMessage($h_monthcal, $MCM_SETCOLOR, $i_color, $i_colorref)
  312.     Else
  313.         $result = GUICtrlSendMsg($h_monthcal, $MCM_SETCOLOR, $i_color, $i_colorref)
  314.     EndIf
  315.     If ($result == -1) Then Return SetError(-1, -1, -1)
  316.  
  317.     $a_result[1] = Int($result) ; COLORREF rgbcolor
  318.     $a_result[2] = "0x" & Hex(String($result), 6) ; Hex BGR color
  319.     $a_result[3] = Hex(String($result), 6)
  320.     $a_result[3] = "0x" & StringMid($a_result[3], 5, 2) & StringMid($a_result[3], 3, 2) & StringMid($a_result[3], 1, 2) ; Hex RGB Color
  321.     Return $a_result
  322. EndFunc   ;==>_GUICtrlMonthCalSetColor
  323.  
  324. ;===============================================================================
  325. ;
  326. ; Description:            _GUICtrlMonthCalSetDelta
  327. ; Parameter(s):        $h_monthcal - controlID
  328. ;                            $i_delta - Value representing the number of months to be set as the control's scroll rate.
  329. ; Requirement:            None.
  330. ; Return Value(s):    Returns an INT value that represents the previous scroll rate.
  331. ; User CallTip:        _GUICtrlMonthCalSetDelta($h_monthcal, $i_delta) Sets the scroll rate for a month calendar control. (required: <GuiMonthCal.au3>)
  332. ; Author(s):            Gary Frost (custompcs at charter dot net)
  333. ; Note(s):                $i_delta
  334. ;                                If this value is zero, the month delta is reset to the default,
  335. ;                                which is the number of months displayed in the control.
  336. ;
  337. ;===============================================================================
  338. Func _GUICtrlMonthCalSetDelta($h_monthcal, $i_delta)
  339.     If Not _IsClassName ($h_monthcal, "SysMonthCal32") Then Return SetError(-1, -1, -1)
  340.     If IsHWnd($h_monthcal) Then
  341.         Return _SendMessage($h_monthcal, $MCM_SETMONTHDELTA, $i_delta)
  342.     Else
  343.         Return GUICtrlSendMsg($h_monthcal, $MCM_SETMONTHDELTA, $i_delta, 0)
  344.     EndIf
  345. EndFunc   ;==>_GUICtrlMonthCalSetDelta
  346.  
  347. ;===============================================================================
  348. ;
  349. ; Description:            _GUICtrlMonthCalSetMaxSelCount
  350. ; Parameter(s):        $h_monthcal - controlID
  351. ;                            $i_maxsel - Value of type int that will be set to represent the maximum number of days that can be selected.
  352. ; Requirement:            None.
  353. ; Return Value(s):    Returns nonzero if successful, or zero otherwise.
  354. ; User CallTip:        _GUICtrlMonthCalSetMaxSelCount($h_monthcal, $i_maxsel) Sets the maximum number of days that can be selected in a month calendar control. (required: <GuiMonthCal.au3>)
  355. ; Author(s):            Gary Frost (custompcs at charter dot net)
  356. ; Note(s):                This will fail if applied to a month calendar control that does not use the $MCS_MULTISELECT style.
  357. ;
  358. ;===============================================================================
  359. Func _GUICtrlMonthCalSetMaxSelCount($h_monthcal, $i_maxsel)
  360.     If Not _IsClassName ($h_monthcal, "SysMonthCal32") Then Return SetError(-1, -1, 0)
  361.     If IsHWnd($h_monthcal) Then
  362.         Return _SendMessage($h_monthcal, $MCM_SETMAXSELCOUNT, $i_maxsel)
  363.     Else
  364.         Return GUICtrlSendMsg($h_monthcal, $MCM_SETMAXSELCOUNT, $i_maxsel, 0)
  365.     EndIf
  366. EndFunc   ;==>_GUICtrlMonthCalSetMaxSelCount